package com.app.controller;


import com.app.entity.User;
import com.app.entity.params.SearchParams;
import com.app.service.UserService;
import com.app.util.PageResult;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zxy
 * @since 2021-03-23
 * 用户
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/addUserByfront")
    public Result addUserByfront(@RequestBody User user) {

        return userService.addUserByfront(user);
    }

    /**
     * 头像上传
     */
    @RequestMapping("/updateUrl")
    public Result updateUrl(@RequestParam("file") MultipartFile file, @RequestParam("id") Integer id) {

        return userService.updateUrl(file, id);
    }
    /**
     * 查询用户信息通过id
     */
    @RequestMapping("/token/findUserByid")
    public Result findUserByid() {
        return userService.findUserByid();
    }
    /**
     * 更新用户
     */
    @RequestMapping("/token/updateUserByid")
    public Result updateUserByid(@RequestBody User user) {
        return userService.updateUserByid(user);
    }

    /**
     * 查询用户通过条件
     */
    @RequestMapping("/token/findUserBySearch")
    public Result findUserBySearch(@RequestBody SearchParams  searchParams) {
        return userService.findUserBySearch(searchParams);
    }

    /**
     * 关注教练
     */
    @RequestMapping("/token/bindCoach")
    public Result bindCoach(@RequestParam("id") Integer id) {
        return userService.bindCoach(id);
    }

    /**
     * 用户提交申请
     */
    @RequestMapping("/token/appleText")
    public Result appleText() {
        return userService.appleText();
    }
    /**
     * 管理员查询用户
     */
    @RequestMapping("/token/findUserByAdmin")
    public PageResult findUserByAdmin(@RequestBody SearchParams searchParams) {
        return userService.findUserByAdmin(searchParams);
    }
    /**
     * 用户通过申请
     * @return
     */
    @RequestMapping("/token/findUserPassByAdmin")
    public Result findUserPassByAdmin(@RequestParam("id") Integer id) {
        return userService.findUserPassByAdmin(id);
    }

    /**
     * 查找所有可用的教练
     */
    @RequestMapping("/token/findCoachAll")
    public Result findCoachAll() {
        return userService.findCoachAll();
    }
}

